/**
 *
 */
package steven.common.android;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.provider.Settings;

/**
 * Get methods are available to all apps. Set Methods are available only to system apps.<br />
 * <br />
 * Required permission: android.permission.WRITE_SECURE_SETTINGS (for set methods)
 *
 * @author steven.lam.t.f
 *
 */
public class SecureUtils{
	protected SecureUtils(){
	}
	public static final boolean isSystemApp(final Context context){
		return (context.getApplicationInfo().flags & ApplicationInfo.FLAG_SYSTEM) != 0;
	}
	public static final boolean isMockLocationAllowed(final Context context){
		return Settings.Secure.getInt(context.getContentResolver(), Settings.Secure.ALLOW_MOCK_LOCATION, 0) == 1;
	}
	public static final void setMockLocationAllowed(final Context context, final boolean allowed){
		if(SecureUtils.isMockLocationAllowed(context) != allowed){
			Settings.Secure.putInt(context.getContentResolver(), Settings.Secure.ALLOW_MOCK_LOCATION, (allowed ? 1 : 0));
		}
	}
	public static final int getLocationMode(final Context context){
		return Settings.Secure.getInt(context.getContentResolver(), Settings.Secure.LOCATION_MODE, Settings.Secure.LOCATION_MODE_OFF);
	}
	public static final void setLocationMode(final Context context, final int mode){
		if(SecureUtils.getLocationMode(context) != mode){
			Settings.Secure.putInt(context.getContentResolver(), Settings.Secure.LOCATION_MODE, mode);
		}
	}
}
